package handler

func Two_number_subtract(a []int, target int) [][]int {
	result := [][]int{}
	hashtable := map[int]int{}
	for i, v := range a {
		if i1, ok := hashtable[target-v]; ok {
			result = append(result, []int{i1, i})
		}
		hashtable[v] = i
	}
	return result
}

func Two_number_add(n1, n2 *ListNode) *ListNode {
	carry := 0
	var head, tail *ListNode
	for n1 != nil || n2 != nil {
		a, b := 0, 0
		if n1 != nil {
			a = n1.Val
		}
		if n2 != nil {
			b = n2.Val
		}
		c := a + b + carry
		if head == nil {
			head = &ListNode{Val: c % 10}
			tail = head
		} else {
			tail.Next = &ListNode{Val: c % 10}
			tail = tail.Next
		}
		carry = c / 10
		if n1 != nil {
			n1 = n1.Next
		}
		if n2 != nil {
			n2 = n2.Next
		}
	}
	if carry > 0 {
		tail.Next = &ListNode{Val: carry}
	}
	return head
}
